<template>
	<view>
		<view class="groupList" v-if="groupArr">
			<view class="groupItem" v-for="(item,index) in groupArr" :key="index" @click="goGroupDetail(item.id)">
				<view class="groupAvatar">
					<image :src="item.avatar" v-if="item.avatar" mode="aspectFill"></image>
					<image src="../../static/images/gugou/icon2.png" v-else mode="aspectFill"></image>
				</view>
				<view class="groupName">
					{{item.name}}
				</view>
			</view>
		</view>
		
		<view class="groupList" v-if="memberGroup">
			<view class="groupItem" v-for="(item,index) in memberGroup" :key="index" @click="goGroupDetail(item.groupId)">
				<view class="groupAvatar">
					<image :src="item.avatar" v-if="item.avatar" mode="aspectFill"></image>
					<image src="../../static/images/gugou/icon2.png" v-else mode="aspectFill"></image>
				</view>
				<view class="groupName">
					{{item.name}}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {getGroupByOpen,getGroupByJoin} from '@/api/group.js'
	export default {
		data() {
			return {
				type:'',
				groupArr:[],
				memberGroup:[],
			};
		},
		onShow(){
			let pages=getCurrentPages()
			this.type=pages[pages.length-1].options.type
			this.getGroupList()
		},
		methods:{
			getGroupList(){
				if(this.type=='leader'){
					getGroupByOpen().then(res=>{
						if(res.data.code==200){
							this.groupArr=res.data.data
						}
					})
				}
				//else{
				// 	getGroupByJoin(this.key).then(res=>{
				// 		if(res.data.code==200){
				// 			this.memberGroup=res.data.data
				// 		}
				// 	})
				// }
			},
			goGroupDetail(id){
				uni.navigateTo({
					url:`/pages/groupDetails/groupDetails?groupId=${id}`
				})
			},
		},
	}
</script>

<style lang="scss">
.groupList{
	.groupItem{
		display: flex;
		align-items: center;
		height: 120rpx;
		.groupAvatar{
			width: 100rpx;
			height: 100rpx;
			overflow: hidden;
			aspect-ratio: 1/1;
			border-radius: 50%;
			margin:0 30rpx;
			background-size: cover;
			image{
				width: 100%;
				height: 100%;
			}
		}
		.groupName{
			margin-left: 20rpx;
			font-size: 34rpx;
		}
	}
}

</style>
